﻿function $import(path, type) {
    var i,
      base,
      src = "globle.js",
      scripts = document.getElementsByTagName("script");

    for (i = 0; i < scripts.length; i++) {
        if (scripts[i].src.match(src)) {
            base = scripts[i].src.replace(src, "");
            break;
        }
    }

    if (type == "css") {
        document.write("<" + "link href=\"" + base + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
    } else {
        document.write("<" + "script src=\"" + base + path + "\"></" + "script>");
    }
}

//Sample: String.format("I am {0}, you are {1}","a","b");
String.format = function() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

//string To Date
String.toDate = function(fmt, str) {
    var patten = /(y|M|d|h|m|s)/g;
    var result = { y: 0, M: 0, d: 0, h: 0, m: 0, s: 0 };
    var r = patten.exec(fmt);
    var currentChar = r[0];
    while (r != null) {
        var a = str.substr(r.index, 1);
        if (currentChar != r[0]) {
            currentChar = r[0];
        }
        result[currentChar] = (result[currentChar] * 10) + parseInt(a);
        r = patten.exec(fmt);
    }
    return new Date(result.y, result.M, result.d, result.h, result.m, result.s);
}
function getAbsPosition(o) {//html object
    // Get an object left position from the upper left viewport corner
    oLeft = o.offsetLeft;             // Get left position from the parent object
    oTop = o.offsetTop;
    while (o.offsetParent != null) {   // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent    // Get parent object reference
        oLeft += oParent.offsetLeft // Add parent left position
        oTop += oParent.offsetTop // Add parent top position
        o = oParent
    }
    return { left: oLeft, top: oTop };
}

$(document).ready(function() {
    iniButtons();
    iniCSSFormInIE6();
    if ($.easyValidate) {
        var setting = "<div class=\"ui-state-error ui-corner-all alertPanel\"><span class=\"ui-icon ui-icon-alert alertIcon\"></span><span class=\"alertText\"></span></div>";
        $.easyValidate({
            summary: true,
            onError: function(message) {
                var a = $(this).next("div.alertPanel");
                if (a.length == 0) {
                    a = $(this).after(setting).next();
                }

                $(".alertText", $(a).addClass("ui-state-error")).text(message.join("<br>"));
                $(a).children("span").addClass("ui-icon-alert").removeClass("ui-icon-check");

            },
            errorEvent: false,
            onCorrect: function() {
                var a = $(this).next("div.alertPanel");
                if (a.length == 0) {
                    a = $(this).after(setting).next();
                }
                $(".alertText", $(a).removeClass("ui-state-error")).text("");
                $(a).children("span").removeClass("ui-icon-alert").addClass("ui-icon-check");
            }
        });
    }
});

// button样色
//--------------------------------------------
function iniButtons() {
   // $("button, input:submit,input:button,.button").button();

}

function iniCSSFormInIE6() {
    if ($.browser.version === "6.0") {
        $(".cssform input[type='text'], .cssform input[type='password'], .cssform textarea")
        .addClass("cssform-input")
        .focus(function() { $(this).addClass("cssform-input-focus") }).blur(
        function() { $(this).removeClass("cssform-input-focus") }
        );
    }
}


//slideMenu
(function($) {

    /*********************
    //* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
    //* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
    //* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
    *********************/

    //Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
    var arrowimages = { down: ['downarrowclass', '/content/images/down.gif', 23], right: ['rightarrowclass', '/content/images/right.gif'] }

    var jqueryslidemenu = {

        animateduration: { over: 200, out: 100 }, //duration of slide in/ out animation, in milliseconds

        buildmenu: function(menuid, arrowsvar) {
            jQuery(document).ready(function($) {
                var $mainmenu = $("#" + menuid + ">ul")
                var $headers = $mainmenu.find("ul").parent()
                $headers.each(function(i) {
                    var $curobj = $(this)
                    var $subul = $(this).find('ul:eq(0)')
                    this._dimensions = { w: this.offsetWidth, h: this.offsetHeight, subulw: $subul.outerWidth(), subulh: $subul.outerHeight() }
                    this.istopheader = $curobj.parents("ul").length == 1 ? true : false
                    $subul.css({ top: this.istopheader ? this._dimensions.h + "px" : 0 })
                    $curobj.children("a:eq(0)").css(this.istopheader ? { paddingRight: arrowsvar.down[2]} : {}).append(
				'<img src="' + (this.istopheader ? arrowsvar.down[1] : arrowsvar.right[1])
				+ '" class="' + (this.istopheader ? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
                    $curobj.hover(
				function(e) {
				    var $targetul = $(this).children("ul:eq(0)")
				    this._offsets = { left: $(this).offset().left, top: $(this).offset().top }
				    var menuleft = this.istopheader ? 0 : this._dimensions.w
				    menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft
				    if ($targetul.queue().length <= 1) //if 1 or less queued animations
				        $targetul.css({ left: menuleft + "px", width: this._dimensions.subulw + 'px' }).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e) {
				    var $targetul = $(this).children("ul:eq(0)")
				    $targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			) //end hover
                }) //end $headers.each()
                $mainmenu.find("ul").css({ display: 'none', visibility: 'visible' })
            }) //end document.ready
        }
    }

    //build menu with ID="myslidemenu" on page:
    jqueryslidemenu.buildmenu("mainMenu", arrowimages)

})($);

function hasPermission(intTotal, intOperator) {
    if (intOperator == 0)
        return false;
    if (intTotal < intOperator)
        return false;
    return (intTotal & intOperator) == intOperator;
}